import { AxiosRequestConfig } from "axios";

export type CodeType = string|number;

export type DataType = any;

export interface BdjfResponse{
    [key: string]: any;
    code:CodeType;
    msg?:string;
    data?:DataType;
    success:boolean;
    isLoading:boolean;
    update:(newRes:BdjfResponse)=>BdjfResponse;
    loading:(data?:DataType)=>BdjfResponse;
}

export interface AttributeMapping {
    code: string;
    msg: string;
    data: string;
}

export interface CacheOption{
    bindCacheKey?: string[];
    conflictCacheUrl?: BdjfRequest[];
}

export interface RequestOption extends AxiosRequestConfig{
    // 重写了 AxiosRequestConfig 中的 url，将其改为必须值
    url:string;
    needCache?:boolean;
    loadingText?:string;
    hideLoading?:boolean;
    hideError?:boolean;
    hideWarn?:boolean;
    attributeMapping?: AttributeMapping;
    rejectError?:boolean;
}

export interface BdjfRequest{
    requestOption:RequestOption;
    cacheOption?:CacheOption;
    closeLoading:()=>BdjfRequest;
    openLoading:()=>BdjfRequest;
    setOption:(newOption:RequestOption)=>BdjfRequest;
    setCacheOption:(newOption:CacheOption)=>BdjfRequest;
    conflictCacheUrl:()=>string[];
}

export interface HttpConfig{

    showLoading:(request:BdjfRequest)=>void;

    hideLoading:(res:BdjfResponse,request:BdjfRequest)=>void;

    showWarn:(res:BdjfResponse,request:BdjfRequest)=>void;

    showError:(res:BdjfResponse,request:BdjfRequest)=>void;

    successCode:CodeType;

    attributeMapping:AttributeMapping;

    openLog?:boolean;

}
